import { http } from "@/utils/http";
import { systemUrlApi } from "@/api/utils";

type Result = {
  success: boolean;
  data?: Array<any>;
};

type ResultTable = {
  /** 列表数据 */
  records: Array<any>;
  /** 总条目数 */
  total?: number;
  /** 每页显示条目个数 */
  size?: number;
  /** 当前页数 */
  current?: number;
};

/** 获取系统管理-用户管理列表 */
export const getUserList = (params?: object) => {
  return http.request<ResultTable>(
    "get",
    systemUrlApi("/system/v1/user/page"),
    { params }
  );
};

/** 用户管理-保存用户 */
export const saveUser = (data?: object) => {
  return http.request<boolean>("post", systemUrlApi("/system/v1/user/save"), {
    data
  });
};

/** 用户管理-删除用户 */
export const deleteUser = (data?: object) => {
  return http.request<boolean>("delete", systemUrlApi("/system/v1/user"), {
    data
  });
};

/** 用户管理-修改用户密码 */
export const updateUserPassword = (data?: object) => {
  return http.request<boolean>(
    "put",
    systemUrlApi("/system/v1/user/update-password"),
    { data }
  );
};

/** 系统管理-用户管理-获取所有角色列表 */
export const getAllRoleList = () => {
  return http.request<Array<any>>(
    "get",
    systemUrlApi("/system/v1/role/list-all-role")
  );
};

/** 系统管理-用户管理-根据userId，获取对应角色id列表（userId：用户id） */
export const getRoleIds = (id: string) => {
  return http.request<Array<string>>(
    "get",
    systemUrlApi("/system/v1/user/user-role-ids/" + id)
  );
};

/** 系统管理-用户管理-更新用户角色绑定关系 */
export const updateUserRole = (data?: object) => {
  return http.request<boolean>(
    "put",
    systemUrlApi("/system/v1/user/user-role-rel"),
    { data }
  );
};

/** 获取系统管理-角色管理列表 */
export const getRoleList = (params?: object) => {
  return http.request<ResultTable>(
    "get",
    systemUrlApi("/system/v1/role/search"),
    { params }
  );
};

/** 修改角色状态 */
export const modifyRoleStatus = (data?: object) => {
  return http.request<boolean>(
    "put",
    systemUrlApi("/system/v1/role/role-status"),
    { data }
  );
};

/** 获取角色管理-权限-菜单权限-根据角色 id 查对应菜单 */
export const getRoleMenuIds = (id: String) => {
  return http.request<[]>(
    "get",
    systemUrlApi("/system/v1/role/role-menu-ids/" + id),
    null
  );
};

export const saveRoleMenu = (data?: object) => {
  return http.request<boolean>(
    "post",
    systemUrlApi("/system/v1/role/role-menu"),
    { data }
  );
};

/** 保存角色 */
export const saveRole = (data?: object) => {
  return http.request<boolean>("post", systemUrlApi("/system/v1/role/save"), {
    data
  });
};

export const deleteRole = (id?: string) => {
  return http.request<number>("delete", systemUrlApi("/system/v1/role/" + id));
};

/** 获取系统管理-菜单管理列表 */
export const getMenuList = (data?: object) => {
  return http.request<Array<any>>(
    "get",
    systemUrlApi("/system/v1/menu/search"),
    { data }
  );
};

/**
 * 增加菜单
 */
export const addMenu = (data?: object) => {
  return http.request<boolean>("post", systemUrlApi("/system/v1/menu"), {
    data
  });
};

/**
 * 修改菜单
 */
export const modifyMenu = (data?: object) => {
  return http.request<boolean>("put", systemUrlApi("/system/v1/menu"), {
    data
  });
};

export const deleteMenu = (id?: string) => {
  return http.request<number>("delete", systemUrlApi("/system/v1/menu/" + id));
};

/** 获取系统管理-部门管理列表 */
export const getDomainList = (params?: object) => {
  return http.request<ResultTable>(
    "get",
    systemUrlApi("/system/v1/domain/page"),
    {
      params
    }
  );
};

/** 获取系统监控-在线用户列表 */
export const getOnlineLogsList = (data?: object) => {
  return http.request<ResultTable>("post", "/online-logs", { data });
};

/** 获取系统监控-登录日志列表 */
export const getLoginLogsList = (data?: object) => {
  return http.request<ResultTable>("post", "/login-logs", { data });
};

/** 获取系统监控-操作日志列表 */
export const getOperationLogsList = (data?: object) => {
  return http.request<ResultTable>("post", "/operation-logs", { data });
};

/** 获取系统监控-系统日志列表 */
export const getSystemLogsList = (data?: object) => {
  return http.request<ResultTable>("post", "/system-logs", { data });
};

/** 获取系统监控-系统日志-根据 id 查日志详情 */
export const getSystemLogsDetail = (data?: object) => {
  return http.request<Result>("post", "/system-logs-detail", { data });
};

/** 获取角色管理-权限-菜单权限 */
export const getRoleMenu = (data?: object) => {
  return http.request<Array<any>>(
    "get",
    systemUrlApi("/system/v1/menu/role-menu"),
    { data }
  );
};

export const getAllDomains = () => {
  return http.request<Array<any>>(
    "get",
    systemUrlApi("/system/v1/domain/all-domains")
  );
};

/** 系统管理-业务域管理-保存业务域 */
export const saveDomain = (data?: object) => {
  return http.request<boolean>("post", systemUrlApi("/system/v1/domain/save"), {
    data
  });
};

/** 系统管理-业务域管理-删除业务域 */
export const deleteDomain = (id?: string) => {
  return http.request<boolean>(
    "delete",
    systemUrlApi("/system/v1/domain/" + id)
  );
};
